package com.bblocks.common.anti_reptile.constant;

import com.bblocks.common.anti_reptile.config.bean.IpRule;
import com.bblocks.common.anti_reptile.config.bean.RuleComm;
import com.bblocks.common.anti_reptile.config.bean.UaRule;
import com.bblocks.common.anti_reptile.config.bean.UserRule;
import lombok.Getter;
import lombok.NonNull;

/**
 * <p>Project: bb-anti-reptile - RuleTypeEnum</p>
 * <p>描述：规则枚举</p>
 *
 * @Author Zhao [125043150@qq.com]
 * @Date 2024/3/23 21:54
 * @Version 1.0
 * @since 8
 */
@Getter
public enum RuleTypeEnum {
    /**
     * ua
     */
    UA(1, "ua", UaRule.class),
    /**
     * 普通ip
     */
    IP(2, "ip", IpRule.class),
    /**
     * ip plus
     */
    IP_PLUS(3, "ip_plus", IpRule.class),
    /**
     * 用户
     */
    USER(4, "user", UserRule.class);


    /**
     * 策略类型
     */
    private Integer type;
    /**
     * 策略名称/描述
     */
    private String desc;
    /**
     * 实现（可以为空）
     */
    private Class<RuleComm> implClass;

     RuleTypeEnum(Integer type, String desc, Class implClass) {
        this.type = type;
        this.desc = desc;
        this.implClass = implClass;
    }


    private static RuleTypeEnum[] types =  RuleTypeEnum.values();
    public static RuleTypeEnum getRuleType(@NonNull Integer type) {
        for (RuleTypeEnum t : types) {
            if (t.type.equals(type) ) {
                return t;
            }
        }
        return null;
    }



}
